import { Controller, Get, Post, Body, Patch, Param, Delete, UseFilters, UseGuards } from '@nestjs/common';
import { ApiBearerAuth, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { TypeormFilter } from 'src/common/filters/typeorm.filter';
import { JwtGuard } from 'src/common/guards/jwt.guard';
import { ClassifyService } from './classify.service';
import { CreateClassifyDto } from './dto/create-classify.dto';
import { UpdateClassifyDto } from './dto/update-classify.dto';
import { ClassifyResultVo } from './vo/classify.result.vo';

@Controller('classify')
@ApiTags('分类')
@UseFilters(new TypeormFilter())
export class ClassifyController {
  constructor(private readonly classifyService: ClassifyService) {}

  @Post()
  @ApiOperation({summary:'新增分类'})
  @ApiResponse({type:Number})
  @ApiBearerAuth()
  @UseGuards(JwtGuard)
  create(@Body() createClassifyDto: CreateClassifyDto) {
    return this.classifyService.create(createClassifyDto);
  }

  @Get()
  @ApiOperation({summary:'分类列表'})
  @ApiResponse({type:ClassifyResultVo})
  @ApiBearerAuth()
  @UseGuards(JwtGuard)
  findAll() {
    return this.classifyService.findAll(true);
  }

  @Get('user')
  @ApiOperation({summary:'分类列表（博客端）'})
  @ApiResponse({type:ClassifyResultVo})
  findAllUser() {
    return this.classifyService.findAll(false);
  }

  @Get(':id')
  @ApiOperation({summary:'分类详情'})
  @ApiResponse({type:ClassifyResultVo})
  @ApiBearerAuth()
  @UseGuards(JwtGuard)
  findOne(@Param('id') id: string) {
    return this.classifyService.findOne(+id,true);
  }

  @Get('user/:id')
  @ApiOperation({summary:'分类详情（博客端）'})
  @ApiResponse({type:ClassifyResultVo})
  findOneUser(@Param('id') id: string) {
    return this.classifyService.findOne(+id,false);
  }

  @Patch(':id')
  @ApiOperation({summary:'分类修改'})
  @ApiResponse({type:null})
  @ApiBearerAuth()
  @UseGuards(JwtGuard)
  update(@Param('id') id: string, @Body() updateClassifyDto: UpdateClassifyDto) {
    return this.classifyService.update(+id, updateClassifyDto);
  }

  @Delete(':id')
  @ApiOperation({summary:'分类删除'})
  @ApiResponse({type:null})
  @ApiBearerAuth()
  @UseGuards(JwtGuard)
  remove(@Param('id') id: string) {
    return this.classifyService.remove(+id);
  }
}
